1 /*
2 Copyright (c)
2014 Andrew Jones, Dario Seyb
3  Based
on 'Spriter2Unity' python code by Malhavok
4
5 Permission
is hereby granted, free of charge, to any person obtaining a copy
6 of
this software and associated documentation files (the "Software"), to deal
7 in
the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software
is
10 furnished to
do so, subject to the following conditions:
11
12 The above copyright notice and
this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */

23 using
UnityEngine;
24 using
System;
25 using
System.Collections.Generic;
26 using
System.Linq;
27 using
System.Text;
28 using
System.Xml;
29 using
UnityEditor;
30
31 namespace
Assets.ThirdParty.Spriter2Unity.Editor.Spriter
32 {
33     
public enum FileType
34     {
35         INVALID_TYPE,
36         Image,
37         SoundEffect,
38         AtlasImage,
39         Entity,
40     }
41
42     
public class File : KeyElem
43     {
44         
public const string XmlKey = "file";
45
46         
public File(XmlElement element, Folder folder)
47             :
base(element)
48         {
49             Parse(element, folder);
50         }
51
52         
public Folder Folder { get; private set; }
53         
public FileType FileType { get; private set; }
54         
public string Name { get; private set; }
55         
public Vector2 Pivot { get; private set; }
56         
public Vector2 Size { get; private set; }
57         
public Vector2 Offset { get; private set; }
58         
public Vector2 OriginalSize { get; private set; }
59
60         
protected virtual void Parse(XmlElement element, Folder folder)
61         {
62             Folder = folder;
63
64             
var type = element.GetString("type", "image");
65             
switch(type)
66             {
67                 
case "image":
68                     FileType = FileType.Image;
69                     
break;
70                 
case "atlas_image":
71                     FileType = FileType.AtlasImage;
72                     
break;
73                 
case "sound_effect":
74                     FileType = FileType.SoundEffect;
75                     
break;
76                 
case "entity":
77                     FileType = FileType.Entity;
78                     
break;
79                 
default:
80                     FileType = FileType.INVALID_TYPE;
81                     
break;
82             }
83
84             Name = element.GetString(
"name", "");
85
86             Vector2 pivot;
87             pivot.x = element.GetFloat(
"pivot_x", 0.0f);
88             pivot.y = element.GetFloat(
"pivot_y", 0.0f);
89             Pivot = pivot;
90
91             Vector2 size;
92             size.x = element.GetInt(
"width", 0);
93             size.y = element.GetInt(
"height", 0);
94             Size = size;
95
96             Vector2 offset;
97             offset.x = element.GetInt(
"offset_x", 0);
98             offset.y = element.GetInt(
"offset_y", 0);
99             Offset = offset;
100
101             Vector2 originalSize;
102             originalSize.x = element.GetInt(
"original_width", 0);
103             originalSize.y = element.GetInt(
"original_height", 0);
104             OriginalSize = originalSize;
105         }
106
107 #
if UNITY_EDITOR
108         
private string FolderName
109         {
110             
get
111             {
112                 
return Name.Substring(0, Name.IndexOf('/') - 1);
113             }
114         }
115
116         
private string ImageName
117         {
118             
get
119             {
120                 
return Name.Substring(Name.IndexOf('/')+1);
121             }
122         }
123
124         
public Vector2 GetPivotOffetFromMiddle()
125         {
126             
var mid = Size / 2;
127             
var pvt = new Vector2(
128                 Size.x * Pivot.x,
129                 Size.y * Pivot.y);
130
131             
return mid - pvt;
132         }
133 #endif
134     }
135 }



Trò chơi đua xe động vật trong UNITY Engine 114.706 lượt xem

Gõ tìm kiếm nhanh...